<template>
  <div class="noticeManage">
    <a-table :columns="columns" :data-source="data" :pagination="pagination" @change="pageChange" :rowKey="rowKey">
    </a-table>
  </div>
</template>

<script>
  import { getServiceTicketList } from "../../serves";

  const columns = [
    {
      title: 'id',
      dataIndex: 'id',
      key: 'id',
      ellipsis: true,
    },
    {
      title: '问题',
      dataIndex: 'content',
      key: 'content',
      ellipsis: true,
    },
    {
      title: '回复',
      dataIndex: 'response',
      key: 'response',
      ellipsis: true,
    },
    {
      title: '提问人',
      dataIndex: 'questioner',
      key: 'questioner',
      ellipsis: true,
    },
    {
      title: '提问人名字',
      dataIndex: 'questionerName',
      key: 'questionerName',
      ellipsis: true,
    },
    {
      title: '回复人',
      dataIndex: 'answerer',
      key: 'answerer',
      ellipsis: true,
    },
    {
      title: '回复人名字',
      dataIndex: 'answererName',
      key: 'answererName',
      ellipsis: true,
    },
    {
      title: '状态',
      dataIndex: 'status',
      key: 'status',
      ellipsis: true,
    },
    {
      title: '提问时间',
      dataIndex: 'createTime',
      key: 'createTime',
      ellipsis: true,
    },
    {
      title: '回复时间',
      dataIndex: 'modifyTime',
      key: 'modifyTime',
      ellipsis: true,
    }
  ];
  export default {
    name: "NoticeManage",
    data() {
      return {
        columns,
        data: [],
        pagination: {
          current: 1,
          total: 0,
          pageSize: 10,
          showSizeChanger: true,
          showTotal: total => `共 ${total} 条`,
          pageSizeOptions: ['10', '20', '30', '40', '50'],
        },
        lastPageSize: 10,
      }
    },
    mounted() {
      this.handleQuery()
    },
    methods: {
      rowKey(record, index) {
        return index
      },
      handleQuery() {
        let params = {
          pageNum: this.pagination.current,
          pageSize: this.pagination.pageSize
        }
        getServiceTicketList(params).then(res => {
          if (res.status == 200 && res.data.status.code == 200) {
            this.data = res.data.data.records
            this.pagination.total = res.data.data.total
          } else if (res.data.status.code == 450) {
            this.$message.warning(res.data.message)
            this.$router.push({path: '/manageLogin'})
          } else {
            this.$message.warning(res.data.message)
          }
        })
      },
      pageChange(val) {
        this.pagination.pageSize = val.pageSize
        if (val.pageSize != this.lastPageSize) {
          this.pagination.current = 1
          this.lastPageSize = val.pageSize
        } else {
          this.pagination.current = val.current
        }
        this.handleQuery()
      },
    }


  }
</script>

<style lang="scss">
  .noticeManage {
    .ant-table-thead > tr > th, .ant-table-tbody > tr > td {
      padding: 10px;
    }
  }

</style>

